﻿<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html lang="ja">
<head>
<title>S_GetLineCountの使用例</title>
<LINK REL="stylesheet" TYPE="text/css" HREF="../sakura.css">
<meta http-equiv="Content-type" content="text/html; charset=UTF-8">
</head>
<body>
<small>
Sakura-Editor Macro Reference
</small>
<h2>S_GetLineCountの使用例</h2>

<pre>
<span style="color:green;">//sample.js</span>
<span style="color:green;">//空行をカウントする</span>
<span style="color:blue;">var</span> iLine = <span style="color:red;">0</span>;
<span style="color:blue;">var</span> iCount = <span style="color:red;">0</span>;
<span style="color:blue;">var</span> iMax = <span style="color:blue;">GetLineCount</span>(<span style="color:red;">0</span>);	<span style="color:green;">//論理行数を取得</span>
<span style="color:blue;">while</span> (++iLine &lt;= iMax){	<span style="color:green;">//全行をループ</span>
    <span style="color:blue;">if</span> (<span style="color:blue;">GetLineStr</span>(iLine).<span style="color:blue;">match</span>(/[^\t ]+/) == <span style="color:red;">0</span>){
        iCount++;
    }
}

<span style="color:blue;">var</span> oWsh = <span style="color:blue;">new</span> ActiveXObject(<span style="color:#800000;">"WScript.Shell"</span>);
oWsh.Popup(iCount, <span style="color:red;">0</span>, <span style="color:#800000;">""</span>, <span style="color:red;">0</span>);
</pre>

<pre>
<span style="color:green;">//sample.ppa
//最大桁数を調べる</span>
<span style="color:blue;">var</span>
    iCount : <span style="color:blue;">integer</span>;
    iLen : <span style="color:blue;">integer</span>;
    iMax : <span style="color:blue;">integer</span>;

<span style="color:blue;">begin</span>
    iCount := <span style="color:blue;">S_GetLineCount</span>(<span style="color:red;">0</span>);   <span style="color:green;">//行数取得</span>

    <span style="color:blue;">while</span> iCount <span style="color:blue;">do</span>
    <span style="color:blue;">begin</span>                    <span style="color:green;">//全行ループ</span>
        iLen := <span style="color:blue;">Length</span>( <span style="color:blue;">S_GetLineStr</span>(iCount) );
        <span style="color:blue;">if</span> iMax &lt; iLen <span style="color:blue;">then</span> iMax := iLen;
        iCount := iCount - <span style="color:red;">1</span>;
    <span style="color:blue;">end</span>;
    <span style="color:blue;">MessageBox</span>(<span style="color:blue;">IntToStr</span>(iMax), <span style="color:#800000;">'最大桁数'</span>, <span style="color:red;">0</span>);
<span style="color:blue;">end</span>;
</pre>

<hr>
</body></html>
